<?php
class Mech_Model_Item extends Zen_Item 
{
	public function __construct() {
		$this->table = new Zend_Db_Table('mech');
		$this->attachBehavior(new Zen_Behavior_Weight($this))
			 ->attachBehavior(new Zen_Behavior_Alias($this));
	}

	public function getList( $page=1, $limit=0, $clause=null ){
		$where = 'active=1 ';
		if ( $clause )	$where .= "and $clause";
		$select = $this->select()->setPage($page)->setLimit($limit)
						->setPaging(true)->setOrder('weight desc');
		$res = $select->getData($where);
	 	$this->_pagecount = $select->getPagecount();
		return $res;
	}
	
	public function getPageCount(){
		return ( $this->_pagecount ) ? $this->_pagecount : 1;
	}
	
	public function getBlock() {
		return $this->getList(1,20);
	}
	
	public function getOne($alias) {
		return $this->select()->getOne("active=1 and alias='$alias'");
	}
	
	public function getMechById($id) {
		if (! $id)	
			return false;
		return $this->select()->getOne("active=1 and id='$id'");
	}
	
	public function getSelectList() {
		$list = $this->select()->getData();
		if (! $list) return false;
		$res = array();
		foreach ($list as $item) {
			$res[$item['id']] = $item['label'];
		}
		return $res;
	}
}